package com.sky.controller.user;

import com.sky.pojo.Merchant;
import com.sky.result.Result;
import com.sky.service.user.MerchantService;
import com.sky.vo.ShopVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

import static com.sky.constant.RedisConstant.SHOP_STATUS_KEY;

@RestController
@RequestMapping("/user/shop")
@Api(tags = "用户端查看状态")

public class UserShopController {

    @Autowired
    private RedisTemplate redisTemplate;
    //导入商品的service
    @Autowired
    private MerchantService merchantService;


    @GetMapping("/status")
    @ApiOperation("查看店铺营业状态")
    public Result getShopStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer o = (Integer)valueOperations.get(SHOP_STATUS_KEY);
        return Result.success(o);
    }
    //TODO 查看店铺信息,我们默认为1
    //  获取店铺电话
    @GetMapping("/getMerchantInfo")
    @ApiOperation("获取商家信息")
    public Result   getMerchantInfo(){
        //  获取唯一商家对象信息
        Merchant merchant = merchantService.getShopById(1L);
        String  shopName = merchant.getShopName();
        String  shopAddress = merchant.getShopAddress();
        String  shopTelephone = merchant.getShopTelephone();
        ShopVO build = ShopVO.builder().phone(shopTelephone).shopName(shopName).shopAddress(shopAddress).build();
        return  Result.success(build);
    }
}
